package logic

import (
	"Wei-Xin/models"
	"context"
	"errors"

	"Wei-Xin/weixinrpc/internal/svc"
	"Wei-Xin/weixinrpc/weixinrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserShowLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUserShowLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserShowLogic {
	return &UserShowLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 个人信息
func (l *UserShowLogic) UserShow(in *weixinrpc.UserShowRequest) (*weixinrpc.UserShowResponse, error) {
	// todo: add your logic here and delete this line

	var user models.User
	models.DB.Debug().Where("id = ?", in.UserId).Find(&user)
	if user.ID == 0 {
		return nil, errors.New("当前用户不存在,查询失败")
	}

	return &weixinrpc.UserShowResponse{
		UserId:    int64(user.ID),
		Account:   user.Account,
		Password:  user.Password,
		Address:   user.Address,
		NickName:  user.NickName,
		HeadImage: user.HeadImage,
	}, nil
}
